package impl

import (
	model2 "gf-xb-api/cwt/filter/model"

	"github.com/gogf/gf/v2/database/gdb"
)

type BetweenRuleParser[T any] struct {
	Op        string
	FieldName string
	Rule      *model2.FilterRule[T]
}

func (p *BetweenRuleParser[T]) Parse(op string, fieldName string, rule *model2.FilterRule[T], m *gdb.Model) *gdb.WhereBuilder {

	builder := m.Builder()

	datas := rule.Datas
	if len(datas) < 2 {
		return builder
	}

	if op == model2.AndOperator {

		return builder.WhereBetween(fieldName, datas[0], datas[1])
	}

	return builder.WhereOrBetween(fieldName, datas[0], datas[1])
}
